import * as mongoose from 'mongoose';

export const DepartmentSchema = new mongoose.Schema({
  corpId: { type: String, index: true },
  deptId: { type: Number, index: true },
  parentId: { type: Number, index: true },
  name: String,
  nameEn: String,
  departmentGroups: { type: mongoose.Schema.Types.Mixed, required: false },
  order: { type: Number, default: 1 },
  status: { type: Number, default: 1 }, // 1-正常 2-禁用
  teamId: Number,
  create_time: { type: Number, default: () => Date.now() },
  update_time: { type: Number, default: () => Date.now() },
}, {
  collection: 'departments',
  timestamps: { currentTime: () => Date.now() }
});

// 添加索引
DepartmentSchema.index({ corpId: 1 });
DepartmentSchema.index({ deptId: 1 });
DepartmentSchema.index({ parentId: 1 });
DepartmentSchema.index({ status: 1 });
DepartmentSchema.index({ create_time: -1 });